package util

import org.apache.spark.sql.Row

object KpiPublic {
   def KpiPublic(row: Row) = {
    //获取关键字段  REQUESTMODE	PROCESSNODE	ISEFFECTIVE	ISBILLING	ISBID	ISWIN	ADORDERID
    val reque = row.getAs[Int]("requestmode")
    val proce = row.getAs[Int]("processnode")
    val iseff = row.getAs[Int]("iseffective")
    val isbil = row.getAs[Int]("isbilling")
    val isbin = row.getAs[Int]("isbid")
    val iswin = row.getAs[Int]("iswin")
    val adord = row.getAs[Int]("adorderid")

    //获取 WinPrice adpayment
    val winpri = row.getAs[Double]("winprice")
    val adpay = row.getAs[Double]("adpayment")

    val adReq = if (reque == 1 && proce == 1) {
      List[Double](1, 0, 0)
    } else if (reque == 1 && proce == 2) {
      List[Double](1, 1, 0)
    } else if (reque == 1 && proce == 3) {
      List[Double](1, 1, 1)
    } else {
      List[Double](0, 0, 0)
    }

    val adRtb = if (iseff == 1 && isbil == 1 && isbin == 1 && adord != 0) {
      List[Double](1, 0, 0, 0)
    } else if (iseff == 1 && isbil == 1 && iswin == 1) {
      List[Double](0, 1, adpay / 1000, winpri / 1000)
    } else {
      List[Double](0, 0, 0, 0)
    }

    val adShow = if (reque == 2 && iseff == 1) {
      List[Double](1, 0)
    } else if (reque == 3 && iseff == 1) {
      List[Double](0, 1)
    } else {
      List[Double](0, 0)
    }
    adReq++adRtb++adShow
  }
}
